//
//  AddressBookNoDataView.swift
//  MoyoungDevice
//
//  Created by 易先生 on 2022/8/26.
//

import UIKit

class AddressBookNoDataView: View {

	override func makeUI() {
		super.makeUI()

		self.addSubview(iconImageView)
        self.addSubview(desclLabel)
		self.addSubview(addAddressBookButton)

		iconImageView.snp.makeConstraints { make in
            make.size.equalTo(CGSize(width: 150, height: 150))
            make.center.equalToSuperview()
		}
        
        desclLabel.snp.makeConstraints { make in
            make.top.equalTo(iconImageView.snp.bottom).offset(20)
            make.leading.equalToSuperview().offset(42)
            make.centerX.equalToSuperview()
        }

		addAddressBookButton.snp.makeConstraints { make in
			make.leading.equalToSuperview().offset(50)
			make.trailing.equalToSuperview().offset(-50)
			make.bottom.equalToSuperview().offset(-80)
		}

	}

    public func configIconWithTitle(icon: String, title: String, desc: String?) {

		addAddressBookButton.setTitle(title, for: .normal)
		iconImageView.image = UIImage(named: icon)
        
        if let text = desc {
            desclLabel.attributedText = text.toAttributed
                .font(Fonts.systemFont(ofSize: 14))
                .foregroundColor(R.color.common_23_text_second())
                .paragraph(setup: { style in
                    style.lineSpacing = 3
                    style.lineBreakMode = .byTruncatingTail
                    style.alignment = .center
                }).rawValue
        }
	}

	private lazy var iconImageView: ImageView = {
		let iconImageView = ImageView()
        iconImageView.contentMode = .scaleAspectFit
		return iconImageView
	}()
    
    public lazy var desclLabel: Label = {
        let label = Label()
        label.textColor = R.color.common_23_text_second()
        label.font = Fonts.systemFont(ofSize: 14)
        label.textAlignment = .center
        label.numberOfLines = 0
        return label
    }()

	public lazy var addAddressBookButton: Button = {
		let button = Button()
        button.setTitleColor(R.color.common_24_button_text(), for: .normal)
        button.titleLabel?.font = Fonts.systemFont(ofSize: 16)
        button.layer.cornerRadius = 6
        button.contentEdgeInsets = UIEdgeInsets(top: 16, left: 0, bottom: 16, right: 0)
        button.backgroundColor = R.color.common_22_button_n()
		return button
	}()
}
